
Imports System

Partial Class Manager_ManagerControls_DocumentTags
    Inherits System.Web.UI.UserControl


    Private mIdentifier As Guid

    Public Property DocumentIdentifier() As Guid
        Get
            If mIdentifier = Guid.Empty AndAlso (ViewState("mIdentifier") IsNot Nothing OrElse Request.QueryString("Id") IsNot Nothing) Then
                If ViewState("mIdentifier") IsNot Nothing Then
                    mIdentifier = CType(ViewState("mIdentifier"), Guid)
                Else
                    ViewState("mIdentifier") = New Guid(Request.QueryString("Id"))
                End If
            End If
            Return mIdentifier
        End Get
        Set(ByVal value As Guid)
            If ViewState("mIdentifier") IsNot Nothing Then Return
            mIdentifier = value
            ViewState("mIdentifier") = value
            Me.Visible = True
            Me.GetDocumentTags()
        End Set
    End Property

    Private Sub GetDocumentTags()
        gvDocumentTags.DataSource = TagLib.Tagging.GetDocumentTags(Me.DocumentIdentifier)
        gvDocumentTags.DataBind()
    End Sub


    Protected Sub gvDocumentTags_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvDocumentTags.RowDeleting
        ' Delete Selected Tag
        Dim tag As String = gvDocumentTags.DataKeys(e.RowIndex).Values(0).ToString
        TagLib.Tagging.DeleteDocumentTag(tag, Me.DocumentIdentifier)
        GetDocumentTags()
    End Sub
End Class
